import { launch } from 'puppeteer-core'

import { config } from 'dotenv';
config()
/**
 * 浏览器对象
 */
export const brower = launch({
    executablePath: process.env.chrome_executablePath,
    headless: eval(process.env.headless as string) as boolean,
    devtools: eval(process.env.devtools as string) as boolean,
    slowMo: eval(process.env.slowMo as string) as number
}).then(async brower => {
    // 连接之后，将所有的页面都关闭(虽然只有一个页面)
    (await brower.pages()).forEach(e => e.close())
    return brower;
}).catch(e => {
    console.log("🚀 ~ file: Spider.ts ~ line 24 ~ Spider ~ e", e)
    console.error("连接浏览器时发生错误,程序退出。");
    process.exit();
});